In this project we are going to use COVID19 dataset we have consisting of data-related cumulative number of confirmed, recovered, and deaths cases. we are going to prepare this dataset to answer these questions: How does Global Spread of the virus look like? How intensive the spread of the virus has been in the countries? Does covid19 national lockdowns and self-isolations in different countries have actually impact on COVID19 transmission? we are going to use Plotly module, which is a great visualization tool in python, in order to plot some insightful and intuitive graphs to answer the questions.
pip install plotly==4.10.0
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import time
# Data urls
dataset_url ="https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv"
df = pd.read_csv(dataset_url)
df.head()
df.tail()
df.shape
Using Choropleth map to Visualize Global Spread of COVID-19 from the first day of the pandemic
df = df[df.Confirmed > 0]
df.head()
df[df.Country == "Australia"].tail()
fig = px.choropleth(df, locations = "Country", locationmode="country names", color = "Confirmed",
animation_frame = "Date")
fig.update_layout(title_text = "Novel coronavirus (COVID19) cases worldwide")
fig.show()
fig = px.choropleth(df, locations = "Country", locationmode="country names", color = "Deaths",
animation_frame = "Date")
fig.update_layout(title_text = "Deaths of coronavirus (COVID19) worldwide")
fig.show()
Visualizing the impact of the national lockdown in Australia on the spread of the virus.
aus_lockdown_start_date = '2020-03-23'
aus_lockdown_a_month_later = '2020-04-26'
vic_lockdown_stage3_start_date = '2020-07-08'
vic_lockdown_stage4_end_date ='2020-09-13'
df_aus = df[df.Country == 'Australia']
df_aus.head()
df_aus['Infection Rate'] = df_aus.Confirmed.diff()
df_aus.head()
fig = px.line(df_aus,x='Date', y=['Confirmed'])
fig.show()
df_aus[['Date','Confirmed']]
fig = px.line(df_aus, x='Date', y='Deaths', title = 'The number of death due to COVID19 in Australia')
fig.show()
Visualizing the impact of the national lockdown in Australia on the infection rate.
fig = px.line(df_aus, x= 'Date', y = 'Infection Rate', title = 'Before and after lockdown in Australia')
fig.add_shape(
dict(
type = "line",
x0 = aus_lockdown_start_date,
y0 = 0,
x1 = aus_lockdown_start_date,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='red',width = 2)
)
)
fig.add_annotation(
dict(
x= aus_lockdown_start_date,
y= df_aus['Infection Rate'].max(),
text = 'starting date of the national lockdown'
)
)
fig.add_shape(
dict(
type = "line",
x0 = aus_lockdown_a_month_later,
y0 = 0,
x1 = aus_lockdown_a_month_later,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='orange',width = 2)
)
)
fig.add_annotation(
dict(
x= aus_lockdown_a_month_later,
y= 500,
text = 'ending date of the national lockdown'
)
)
fig.add_shape(
dict(
type = "line",
x0 = vic_lockdown_stage3_start_date ,
y0 = 0,
x1 = vic_lockdown_stage3_start_date,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='red',width = 2)
)
)
fig.add_annotation(
dict(
x= vic_lockdown_stage3_start_date,
y= df_aus['Infection Rate'].max(),
text = 'starting date of the vic stage 3 lockdown'
)
)
fig.add_shape(
dict(
type = "line",
x0 = vic_lockdown_stage4_end_date,
y0 = 0,
x1 = vic_lockdown_stage4_end_date,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='orange',width = 2)
)
)
fig.add_annotation(
dict(
x= vic_lockdown_stage4_end_date,
y= 680,
text = 'ending date of the vic stage 4 lockdown'
)
)
Visualizing the impact of the national lockdown in Australia on the death rate.
df_aus.head()
df_aus['Deaths Rate'] = df_aus.Deaths.diff()
df.head()
Normalise the Infection rate and Deaths rate
df_aus['Infection Rate'] = df_aus['Infection Rate']/df_aus['Infection Rate'].max()
df_aus['Deaths Rate'] = df_aus['Deaths Rate']/df_aus['Deaths Rate'].max()
fig = px.line(df_aus,x='Date', y=['Infection Rate','Deaths Rate'], title = 'Before and After lockdown in Australia')
fig.add_shape(
dict(
type = "line",
x0 = aus_lockdown_start_date,
y0 = 0,
x1 = aus_lockdown_start_date,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='Green',width = 2)
)
)
fig.add_annotation(
dict(
x= aus_lockdown_start_date,
y= df_aus['Infection Rate'].max(),
text = 'starting date of the national lockdown'
)
)
fig.add_shape(
dict(
type = "line",
x0 = aus_lockdown_a_month_later,
y0 = 0,
x1 = aus_lockdown_a_month_later,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='orange',width = 2)
)
)
fig.add_annotation(
dict(
x= aus_lockdown_a_month_later,
y= 0.95,
text = 'ending date of the national lockdown'
)
)
fig.add_shape(
dict(
type = "line",
x0 = vic_lockdown_stage3_start_date ,
y0 = 0,
x1 = vic_lockdown_stage3_start_date,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='Green',width = 2)
)
)
fig.add_annotation(
dict(
x= vic_lockdown_stage3_start_date,
y= df_aus['Infection Rate'].max(),
text = 'starting date of the vic stage 3 lockdown'
)
)
fig.add_shape(
dict(
type = "line",
x0 = vic_lockdown_stage4_end_date,
y0 = 0,
x1 = vic_lockdown_stage4_end_date,
y1 = df_aus['Infection Rate'].max(),
line = dict(color='orange',width = 2)
)
)
fig.add_annotation(
dict(
x= vic_lockdown_stage4_end_date,
y= 0.95,
text = 'ending date of the vic stage 4 lockdown'
)
)